package day11.console.impl;

import day11.console.ConsoleCommand;
import day11.packet.request.JoinGroupRequestPacket;
import day11.util.IDUtil;
import io.netty.channel.Channel;

import java.util.Scanner;

/**
 * @author chenshijie
 * @date 2024/1/2 11:57
 */

public class JoinGroupConsoleCommand implements ConsoleCommand {
    @Override
    public void exec(Scanner sc, Channel channel) {
        JoinGroupRequestPacket joinGroupRequestPacket = new JoinGroupRequestPacket();
        System.out.println("输入GroupId，加入群聊: ");
        String groupId = sc.nextLine();
        if (groupId == null || !IDUtil.isNumeric(groupId)) {
            System.err.println("输入群号不符合格式");;
        } else {
            joinGroupRequestPacket.setGroupId(Integer.parseInt(groupId));
            channel.writeAndFlush(joinGroupRequestPacket);
        }

    }
}
